package com.mall4j.cloud.user.controller.multishop;

import com.mall4j.cloud.common.response.ServerResponseEntity;
import com.mall4j.cloud.user.model.UserCards;
import com.mall4j.cloud.user.service.UserCardsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("multishopUserCardsController")
@Api(tags = "店铺-用户银行卡")
@RequestMapping("/m/userCards")
public class UserCardsController {

    @Autowired
    private  UserCardsService userCardsService;


    //绑卡
    @PostMapping("/bind")
    @ApiOperation(value = "绑卡", notes = "传usercards实体绑卡")
    public ServerResponseEntity<UserCards> bindUserCard(@RequestBody UserCards userCards) {
        UserCards createdUserCards = userCardsService.addUserCards(userCards);
        return ServerResponseEntity.success(createdUserCards);
    }

    //解绑
    @PostMapping("/unbind")
    @ApiOperation(value = "解绑", notes = "根据usercards id解绑")
    public ServerResponseEntity<String> unbindUserCard(@RequestBody  UserCards userCards) {
        userCardsService.deleteUserCardsById(userCards.getId());
        return ServerResponseEntity.success("解绑成功");
    }

    //查看绑定的银行卡
    @GetMapping("/get")
    @ApiOperation(value = "获取用户绑卡列表", notes = "根据userId获取绑卡列表")
    public ServerResponseEntity<List<UserCards>> getUserCards(@RequestParam("userId") Long userId){
        System.out.println(userCardsService.getUserCardsByUserId(userId));
        return ServerResponseEntity.success(userCardsService.getUserCardsByUserId(userId));
    }



    @PostMapping("/recharge")
    public ServerResponseEntity<String> recharge(@RequestParam("cardId") Long cardId, @RequestParam("amount") Double amount) {
        // TODO: Implement recharge logic
        // Example: userCardsService.recharge(cardId, amount);
        return ServerResponseEntity.success("Recharge successful");
    }

    @PostMapping("/withdraw")
    public ServerResponseEntity<String> withdraw(@RequestParam("cardId") Long cardId, @RequestParam("amount") Double amount) {
        // TODO: Implement withdrawal logic
        // Example: userCardsService.withdraw(cardId, amount);
        return ServerResponseEntity.success("Withdrawal successful");
    }
}
